﻿using System;
using System.Windows.Input;
using System.Windows;
using Gencode.VECore.VectorShape;

namespace Gencode.VECore.Tools
{
	public class LineTool : FactoryTool
	{

        protected override VECShape CreateShape(Point mousePosition)
        {
            var shape = new VECLine(mousePosition.X, mousePosition.Y, mousePosition.X, mousePosition.Y);

            shape.StrokeThickness = ToolProperty.StrokeThickness;
            shape.Stroke = ToolProperty.Stroke;
            //shape.Opacity = 255;
            
            return shape;
        }

        public override void OnMouseLeftButtonUp(CanvasDocument sender, MouseButtonEventArgs e)
		{
            //Add object to history
            var shape = sender.SelectedLayer.ShapeList[0] as VECLine;
            if (shape != null)
                sender.AddCommandToHistory(new Gencode.VECore.History.AddCommand(shape));
		}

        public override void OnMouseMove(CanvasDocument sender, MouseEventArgs e)
		{
			if (e.LeftButton == MouseButtonState.Pressed)
			{
				Point m = Mouse.GetPosition(sender);
                var shape = sender.SelectedLayer.ShapeList[0] as VECLine;
                if (shape != null)
                    shape.MoveHandle(m, 2);
			}
		}
	}
}
